package com.esunny.online.service.impl;

import com.esunny.online.dao.RecordDao;
import com.esunny.online.domain.entity.Record;
import com.esunny.online.service.RecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * @author hp
 */
@Service
public class RecordServiceImpl implements RecordService {

    @Resource
    RecordDao recordDao;

    /**
     * 通过用户名和资源id获取播放记录
     * @param username 用户名
     * @param id 资源id
     * @return 播放记录
     */
    @Override
    public Record getVideoRecord(String username, int id) {
        return recordDao.getVideoRecord(username, id);
    }

    /**
     * 更新播放记录/没有则添加记录
     * @param record 播放记录
     * @return 播放记录
     */
    @Override
    public Boolean updateVideoRecord(Record record) {
        Record videoRecord = recordDao.getVideoRecord(record.getUser(), record.getResource());
        int flag;
        System.out.println(record);
        if (videoRecord != null){
             flag = recordDao.updateVideoRecord(record);
        }else{
            flag = recordDao.addVideoRecord(record);
        }
        return 1 == flag;
    }
}
